package com.five.taotao.guide;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.TextView;

import com.five.taotao.R;
import com.five.taotao.guide_classify.LeftFragment;
import com.five.taotao.guide_classify.RightFragment;
import com.five.taotao.search.SearchResultActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * A simple {@link Fragment} subclass.
 */
public class ClassifyFragment extends Fragment {

    @BindView(R.id.search)
    EditText editText;

    @OnClick(R.id.message_search)
    public void search(View v) {
        Intent intent = new Intent(getActivity(), SearchResultActivity.class);
        intent.putExtra("search_name",editText.getText().toString());
        startActivity(intent);
    }

    private View v;
    public LeftFragment left_frgment;
    public RightFragment right_frgment;

    public ClassifyFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        if (v == null) {
            v = inflater.inflate(R.layout.fragment_classify, container, false);
            ButterKnife.bind(this,v);
            left_frgment = (LeftFragment)  getChildFragmentManager().findFragmentById(R.id.left_fragment);
            right_frgment = (RightFragment) getChildFragmentManager().findFragmentById(R.id.right_fragment);

            editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
                @Override
                public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                    if (actionId == EditorInfo.IME_ACTION_SEARCH || (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
                        Intent intent = new Intent(getActivity(), SearchResultActivity.class);
                        intent.putExtra("search_name",editText.getText().toString());
                        startActivity(intent);
                        return true;
                    }
                    return true;
                }
            });
        }
        return v;
    }

}
